<?php
/*
*   Template name:  Поездка
*   Template post type: travel
*/
$trips = carbon_get_post_meta( $post->ID, 'trips');
$description = carbon_get_post_meta( $post->ID, 'description');
// pr($trips);
get_header();

if($trips):
    if(count($trips) > 1):
?>
        <ul class="tab">
            <?php foreach($trips as $trip):?>
            <li>
                <a href="#tab-<?php echo $trip['number_days_trip'] ?>" class="<?php echo ($trip['number_days_trip'] == 1) ? 'active' : '' ;?>"> <?php echo $trip['number_days_trip'] . number_word( $trip['number_days_trip'])?></a>
            </li>
            <?php endforeach ?>
        </ul>
    <?php endif ?>
    <?php foreach($trips as $trip):
    $i = 1;
    

    ?>
    
        <main class="content content_product<?php echo (count($trip) > 1) ? ' faded in' : '' ;?> <?php echo ($i == 1) ? 'content_active' : '' ; ?>"id="tab-<?php echo $trip['number_days_trip']?>" >
            <div class="plan">
                <div class="plan_table">
                    <?php if($trip['data_time_trips']):?>
                        <?php foreach($trip['data_time_trips'] as $data_time_trips): ?>
                        <?php 
                            $date_departure_trips = new DateTime($data_time_trips['data_departure_trips']); 
                            $gathering_time_trips = new DateTime($data_time_trips['gathering_time_trips']); 
                            $departure_time_trips = new DateTime($data_time_trips['departure_time_trips']); 
                        
                        ?>
                            <table class="plan__collected">
                                <tr>
                                    <th align="left" colspan="2"><?php echo $date_departure_trips->format('d.m.Y');?></th>
                                </tr>
                                <tr class="plan__header">
                                    <td colspan="2"><?php echo $data_time_trips['gathering_place']?></td>
                                </tr>
                                <tr class="plan__boarding">
                                    <td class="plan__data">Посадка <?php echo $gathering_time_trips->format('H:i');?></td>
                                    <td class="plan__data">Отъезд <?php echo $departure_time_trips->format('H:i');?></td>
                                </tr>
                            </table>
                        <?php endforeach; $i++;?>
                    <?php endif ?>
                <div class="plan__description">
                    <p> <?php echo $description ?></p>
                </div>
            </div>
            <div class="cardsDescription">
                <?php if($trip['event']):?>
                <?php foreach($trip['event'] as $event):?>
                <?php $img = wp_get_attachment_image_url( $event['foto_event'] , 'large');?>
                <div class="cardsDescription__data">
                    <div class="cardsDescription__img ">
                        <img src="<?php echo $img?>" alt="">
                    </div>
                    <div class="cardsDescription__description">
                        <?php if($event['taitel_event']):?>
                        <h2><?php echo $event['taitel_event']?></h2>
                        <?php endif?>
                        <?php if($event['description_event']):?>
                        <p>
                           <?php echo $event['description_event']?>
                        </p>
                        <?php endif?>
                        <?php if($event['list_event']):?>
                        <p>
                            <?php echo $event['list_event']?>
                        </p>
                        <?php endif?>
                    </div>
                </div>
                <?php endforeach?>
                <?php endif?>
            </div>
        </main>
    <?php endforeach?>
<?php 
    endif;
    if ( comments_open() || get_comments_number() ) :
        comments_template( '', true );
        comment_form(  );
	endif;
?>

<?php

    get_footer();